﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class cms_roles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnNewRow_Click(object sender, EventArgs e)
    {
        gvRoles.ShowFooter = true;
    }
    protected void lbtCancel_Click(object sender, EventArgs e)
    {
        gvRoles.ShowFooter = false;
    }
    protected void lbtInsert_Click(object sender, EventArgs e)
    {
        string roleName = string.Empty;
        TextBox txt = (TextBox)gvRoles.FooterRow.FindControl("txtRoleName");
        try
        {
            roleName = txt.Text;
        }
        catch {}
        if (string.IsNullOrEmpty(roleName)) return;
        Roles.CreateRole(roleName);
        Response.Redirect("roles.aspx");
    }
    protected void btnDelete_Click(object sender, ImageClickEventArgs e)
    {
        string roleName = string.Empty;
        ImageButton theBut = (ImageButton)sender;
        for (int i = 0; i < gvRoles.Rows.Count; i++)
        {
            ImageButton curBut = (ImageButton)gvRoles.Rows[i].FindControl("btnDelete");
            if (theBut.UniqueID == curBut.UniqueID)
            {
                Label lbl = (Label)gvRoles.Rows[i].FindControl("lblRoleName");
                roleName = lbl.Text;
                break;
            }
        }
        Roles.DeleteRole(roleName);
        Response.Redirect("roles.aspx");
    }
}
